<?php

/**
 * This is the model class for table "hs_suggest".
 *
 * The followings are the available columns in table 'hs_suggest':
 * @property integer $id
 * @property string $name
 * @property string $title
 * @property string $content
 * @property string $submit_time
 * @property integer $is_reply
 * @property string $reply_content
 * @property string $reply_time
 */
class Suggest extends CActiveRecord
{
	
	public $verifyCode; //为 Model 设置一个新的属性
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Suggest the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'hs_suggest';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, title, content, submit_time, is_reply', 'required'),
			array('is_reply', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>32),
			array('title', 'length', 'max'=>128),
			array('reply_content, reply_time', 'safe'),
			array('submit_time', 'default', 'value'=>date('Y-m-d H:i:s')),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, title, content, submit_time, is_reply, reply_content, reply_time', 'safe', 'on'=>'search'),
			array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(), 'message'=>'验证码输入错误！'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => '姓名',
			'title' => '主题',
			'content' => '内容',
			'submit_time' => '提交时间',
			'is_reply' => '是否回复',
			'reply_content' => '回复内容',
			'reply_time' => '回复时间',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('content',$this->content,true);
		$criteria->compare('submit_time',$this->submit_time,true);
		$criteria->compare('is_reply',$this->is_reply);
		$criteria->compare('reply_content',$this->reply_content,true);
		$criteria->compare('reply_time',$this->reply_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function beforeSave()
	{
		$this->submit_time = date('Y-m-d H:i:s');
		return true;
	}
}